package main



import (
  "regexp"
  "strings"
  "fmt"
)




func ReplaceLegend(label string, labelMap map[string]string) (string){
    //去除空格
    //label = strings.ReplaceAll(label, " ", "")
    reg := regexp.MustCompile(`(?U){{( *\w+ *)}}`)
    // [[{{mount}} mount] [{{instance}} instance]]
    tmpList := reg.FindAllStringSubmatch(label, -1)
    fmt.Println(1111, tmpList)
    if len(tmpList) == 0{
        return label
    }
    var v string
    var ok bool
    for _, vList := range tmpList{
        if len(vList) < 2{
            continue
        }else{
            v , ok = labelMap[strings.TrimSpace(vList[1])]
            if ok{
                label = strings.ReplaceAll(label, vList[0], v)
            }else{
                continue
            }
        }
    }
    return label
}


func main(){
    label := "{{ pod }}"
    labelMap := map[string]string{
        "pod": "/app",
    }

    fmt.Println(ReplaceLegend(label, labelMap))
}
